package cn.gjxblog.validation.spring.demo1;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.validation.*;

import java.util.Date;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {RootConfig.class})
public class TestValidator {

    @Autowired
    private SmartValidator smartValidator;

    /**
     * 初体验Spring Validator的使用
     */
    @Test
    public void test1(){

        Person person = new Person();
        person.setAge(-1);
        person.setStart(new Date());

        Errors errors = new DirectFieldBindingResult(person, "person");

        ValidationUtils.invokeValidator(smartValidator,person,errors,Person.Complex.class);

        System.out.println(errors);
    }
}
